const { BrowserWindow } = require('electron');
const path = require('node:path')
let tooltipWindow = null;

let currentBindUid = null
let currentFansUid = null

function getBindToCurrentUid() {
	return currentBindUid
}

function getBindToCurrentFansUid() {
	return currentFansUid
}

function showBindTo(fans_id, user_id, x, y, h) {

	if (tooltipWindow && !tooltipWindow.isDestroyed()) tooltipWindow.close();
	tooltipWindow = new BrowserWindow({
		width: 200,
		height: h,
		x: 100 + x,
		y: y,
		frame: false,
		// transparent: true,
		resizable: false,
		show: true,
		alwaysOnTop: true,
		backgroundColor: "#272730",
		webPreferences: {
			preload: path.join(__dirname, 'preload.js')
		}
	})
	
	// 当窗口失去焦点时关闭
	tooltipWindow.on('blur', () => {
		tooltipWindow.close()
	})
	currentFansUid = fans_id
	currentBindUid = user_id
	tooltipWindow.loadURL('http://localhost:8080/#/pages/bind-to-page/bind-to-page?type=1')
}

function hideBindTo() {
	console.log(222)
	currentBindUid = null
	currentFansUid = null
	if (tooltipWindow && !tooltipWindow.isDestroyed()) {
		tooltipWindow.close();
		tooltipWindow = null;
	}
}

module.exports = { showBindTo, hideBindTo, getBindToCurrentUid, getBindToCurrentFansUid };